//
//  LZThirdPartyView.m
//  laziz_Consumer
//
//  Created by ZhaoDongBo on 2016/10/24.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZThirdPartyView.h"
#import "Masonry.h"
#import "BlocksKit+UIKit.h"

@implementation LZThirdPartyView

- (instancetype)init{
    
    self = [super init];
    
    if (self) {
    
        [self setup];
    }
    
    return self;
}

- (void)setup {

    WS(weakSelf);

    [self addSubview:self.line];
    [self addSubview:self.facebookButton];
    [self addSubview:self.twitterButton];
    
    [self.line makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(16);
        make.centerX.mas_equalTo(weakSelf.centerX);
        make.width.mas_equalTo(1);
        make.bottom.mas_equalTo(-16);
    }];
    
    [self.facebookButton makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.trailing.mas_equalTo(weakSelf.line.mas_leading);
    }];
    
    [self.twitterButton makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(weakSelf.line.mas_trailing);
        make.trailing.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
}

#pragma mark - setter/getter

- (UIView *)line {
    
    if (_line == nil) {
        _line = [[UIView alloc] init];
        _line.backgroundColor = UIColorFromRGB(0x818383, 1);
    }
    
    return _line;
}

- (UIButton *)facebookButton {
    
    if (_facebookButton == nil) {
        
        _facebookButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _facebookButton.backgroundColor = [UIColor clearColor];
        _facebookButton.tag             = LZLOGIN_THIRDPARTYLOGIN_FACEBOOK;
        [_facebookButton setImage:[UIImage imageNamed:@"lz_facebook_icon"] forState:UIControlStateNormal];

        WS(weakSelf);
        [_facebookButton bk_addEventHandler:^(UIButton * sender) {
            
            if (weakSelf.thirdPartyLoginButtonActionBlock) {
                weakSelf.thirdPartyLoginButtonActionBlock(LZLOGIN_THIRDPARTYLOGIN_FACEBOOK);
            }
            
        } forControlEvents:UIControlEventTouchUpInside];
    }
    
    return _facebookButton;
}

- (UIButton *)twitterButton {
    
    if (_twitterButton == nil) {
        _twitterButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _twitterButton.backgroundColor  = [UIColor clearColor];
        _twitterButton.tag              = LZLOGIN_THIRDPARTYLOGIN_TWITTER;
        [_twitterButton setImage:[UIImage imageNamed:@"lz_twitter_icon"] forState:UIControlStateNormal];
        
        WS(weakSelf);
        [_twitterButton bk_addEventHandler:^(UIButton * sender) {
            
            if (weakSelf.thirdPartyLoginButtonActionBlock) {
                weakSelf.thirdPartyLoginButtonActionBlock(LZLOGIN_THIRDPARTYLOGIN_TWITTER);
            }
            
        } forControlEvents:UIControlEventTouchUpInside];
    }
    
    return _twitterButton;
}

@end
